//
//  MyCollectionVideoCell.m
//  OnionHome
//
//  Created by fengjie on 2019/9/27.
//  Copyright © 2019 FengJie. All rights reserved.
//

#import "MyCollectionVideoCell.h"

@interface MyCollectionVideoCell ()

/**用户视图*/
@property (nonatomic,strong)UserIconAndNameView*userView;
/**bottomView*/
@property (nonatomic,strong)ShareNewsPraiseView*bottomView;
/**头部文字*/
@property (nonatomic,strong)UILabel*titleLabel;
/**播放视图父视图*/
@property (nonatomic,strong) UIImageView *IMGView;
/**播放按钮*/
@property (nonatomic,strong)UIButton * stopBtn;

@end

@implementation MyCollectionVideoCell


-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self createUI];
    }
    return self;
}
-(void)createUI{
    self.IMGView = UIImageView.new;
    self.IMGView.userInteractionEnabled = YES;
    
    self.playerBgView = UIView.new;
    self.playerBgView.userInteractionEnabled = YES;
    self.playerBgView.hidden = YES;
    
    [self addSubview:self.IMGView];
    [self addSubview:self.playerBgView];
    [self addSubview:self.titleLabel];
    [self addSubview:self.userView];
    [self addSubview:self.bottomView];

    self.stopBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.stopBtn setBackgroundImage:IMAGE_NAMED(@"video_play") forState:UIControlStateNormal];
    kWeakSelf(weakSelf);
    [self.stopBtn addActionHandler:^{
        weakSelf.playerBgView.hidden = NO;
        [weakSelf playAction];
    }];
    
    [self.userView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.right.mas_equalTo(0);
        
    }];
    
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(16);
        make.top.mas_equalTo(self.userView.mas_bottom);
        make.right.mas_equalTo(-16);
    }];
    
    [self.IMGView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(0);
        make.height.mas_equalTo(210);
        make.top.mas_equalTo(self.titleLabel.mas_bottom).offset(16);
    }];
    
    [self.playerBgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.right.bottom.mas_equalTo(self.IMGView);
    }];
    
    [self.bottomView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.bottom.right.mas_equalTo(0);
        make.top.mas_equalTo(self.IMGView.mas_bottom);
    }];
    
    
    [self.IMGView addSubview:self.stopBtn];

    
    [self.stopBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.mas_equalTo(0);
    }];
    
    
}

-(UserIconAndNameView*)userView{
    if(!_userView){
        _userView=[[UserIconAndNameView alloc] initWithFrame:CGRectZero];
        _userView.deleButton.hidden = YES;
    }
    return _userView;
}

-(UILabel*)titleLabel{
    if(!_titleLabel){
        _titleLabel=[UILabel new];
        _titleLabel.textColor = UIColorFromRGB(0x273323);
        _titleLabel.font = SYSTEMFONT(18);
        _titleLabel.numberOfLines = 2;
        _titleLabel.attributedText = [TitleTool getAttributeStringLineSpacing:4 title:@"今天晚上做了法式薄煎饼，简单容易上手，老人孩子都喜欢吃，美味又健康，在家…" titleColor:nil titleFont:nil];
    }
    return _titleLabel;
}
-(ShareNewsPraiseView*)bottomView{
    if(!_bottomView){
        _bottomView=[[ShareNewsPraiseView alloc] initWithFrame:CGRectZero];
    }
    return _bottomView;
}

-(void)setModel:(PlayModel *)model{
    _model = model;
    [self.IMGView imageViewWithUrl:model.pictureUrl placeholderImage:@"dynamicDefut"];
}
-(void)setSelected:(BOOL)selected animated:(BOOL)animated{
    [super setSelected:selected animated:animated];
}
- (void)setStopPlay:(BOOL)stopPlay
{
    _stopPlay = stopPlay;
    self.playerBgView.hidden = stopPlay;
}
- (void)playAction {
    
    if (_delegate && [_delegate respondsToSelector:@selector(cl_tableViewCellPlayVideoWithCell:)]){
        [_delegate cl_tableViewCellPlayVideoWithCell:self];
    }
}
@end
